package com.qidian.buy.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2023/9/13 10:10
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        RestTemplateBuilder builder = new RestTemplateBuilder();
        // 设置链接超时时间
        builder.setConnectTimeout(Duration.ofSeconds(6));
        // 读取数据的超时时间
        builder.setReadTimeout(Duration.ofSeconds(6));
        return builder.build();
    }
}
